package com.mp.approvalreq.servlet;

import com.alibaba.fastjson.JSONObject;
import com.mp.approvalreq.service.TemplateServicePrx;
import com.mp.user.entity.User;
import com.qq.tars.client.util.ServantUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/sortTemplateGroup")
public class SortTemplateGroup extends AbstractServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            User user = getReqUser(req);

            String reqBody = getContent(req);
            JSONObject jo = JSONObject.parseObject(reqBody);
            List<Integer> list = JSONObject.parseArray(jo.getString("ids"), Integer.class);

            TemplateServicePrx templateServicePrx = ServantUtils.getObject(TemplateServicePrx.class);
            templateServicePrx.sortTemplateFolder(user.getCompanyId(), list);

            printSuccessJson(resp);
        } catch (Throwable throwable) {
            onThrowable(req, resp, throwable);
        }
    }
}
